<template>
	<view class="content">
		<image class="logo" src="/static/RTAB8$_R7R6@A9_@X~4~3TQ.png"></image>
		<div class='ctx'>
			<button @click="updateLocationFn" type='primary'>修改位置</button>
			<!-- <navigator url="/pages/about/about"> -->
			<button type="primary" @click="outLogin">退出登录</button>
			<button type="warn" @click="delAccountFn">注销账号</button>
			<!-- </navigator> -->
		</div>

	</view>
</template>

<script>
	import {
		myCheckToken
	} from '@/apis/login.js';
	import {
		delAccount
	} from '@/apis/mobile.js';
	export default {
		data() {
			return {};
		},
		async onLoad() {
			const res = await myCheckToken(uni.getStorageInfoSync('token'));
			console.log('myCheckToken=====', res);
		},
		methods: {
			// 退出账号
			outLogin() {
				uni.showModal({
					title: '警告',
					content: '是否退出登录',
					success: async res => {
						if (res.confirm) {
							console.log('用户点击确定');
							// 清除本地token
							uni.removeStorageSync('token');
							// 成功弹窗
							uni.showToast({
								title: '退出登录成功',
								icon: 'success',
								duration: 2000
							});
							// 跳转登录页
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/login/login'
								});
							}, 2000)

						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			// 注销账号
			async delAccountFn() {
				// 108.267726,22.842727
				uni.showModal({
					title: '警告',
					content: '是否注销账号',
					success: async res => {
						if (res.confirm) {
							console.log('用户点击确定');
							// 删除账号
							const res = await delAccount();
							if (!res.data.success) {
								return uni.showToast({
									title: res.data.msg,
									icon: 'error',
									duration: 2000
								});
							}
							// 清除本地token
							uni.removeStorageSync('token');
							// 成功弹窗
							uni.showToast({
								title: res.data.msg,
								icon: 'success',
								duration: 2000
							});
							// 跳转登录页
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/login/login'
								});
							}, 2000)
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},

			updateLocationFn() {
				uni.navigateTo({
					url: '/pages/updateLocation/updateLocation'
				});
			}
		}
	};
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.ctx {
		// height: 200rpx;

		>button {
			margin-bottom: 20rpx;
		}
	}

	.logo {
		height: 400rpx;
		width: 400rpx;
		margin-top: 100rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}
</style>
